home *** CD-ROM | disk | FTP | other *** search
/ Programming Sound Cards / Programming Sound Cards.iso / sound_30 / record.c < prev    next >
C/C++ Source or Header  |  1995-01-01  |  3KB  |  111 lines

  1. #include <stdio.h>
  2. #include "midi.h"
  3. /* 
  4. Copright 1988, G.E.S. Consulting
  5.  
  6. INTERRUPT MODE tutorial, RECORD and PLAY
  7.  
  8.  
  9. NOTE:
  10. struct eventlist {
  11.     struct event *f; ptr to first event on que
  12.     struct event *c; ptr to current event on que
  13.     struct event *l; ptr to last event on que
  14.     }
  15. Library does NOT maintain  (or have knowledge of) this structure.
  16. You are free to devise you own way to manage event lists if you wish.
  17. */
  18.  
  19. main(ac,av)
  20. char **av;
  21.     {
  22.     char *ofile; /* output file name */
  23.     static struct eventlist elist; /* anchor for ques */
  24.     int x,i;
  25.     
  26.     if (ac > 1)
  27.         ofile = av[1];
  28.     else
  29.         ofile = "events.lst";
  30.     
  31.     mpu_init(); /* install the driver */
  32.     
  33.     init_event_list(14); /* allocate 14,000 events for demo */
  34.     
  35.     reset_mpu(); /* get mpu401 into a known state */
  36.     
  37.     if ((i = get_version()) < 0) /* see if one is there */
  38.         {
  39.         printf("MPU401 not FOUND\n");
  40.         exit(1);
  41.         }
  42.     
  43.     all_thru_off();
  44.     
  45.     midi_thru(OFF); /* keep input from echoing to output
  46.                     assumes keyboard is in local mode */
  47.     
  48.     set_record_que(&elist.f); /* tell driver where to put stuff */
  49.     
  50.     printf("Press any key to start recording\n"); /* ready, set... */
  51.     getch();
  52.     
  53.     record_start(); /* go */
  54.     
  55.     printf("Press any key to Stop Recording\n");
  56.     printf("Events Remaining: ");
  57.     
  58.     while(!kbhit()) /* keep user posted as to how much room is left */
  59.         {
  60.         printf("%06ld\b\b\b\b\b\b",events_available());
  61.         }
  62.     getch(); /* all done */
  63.     printf("\n");
  64.     
  65.     record_stop(); /* stop recording */
  66.     
  67.     do /* quick review */
  68.         printf("Play back before saving? (y/n) ");
  69.     while((i=(getch()&0x7f)) != 'y' && i != 'n');
  70.     printf("\n");
  71.     
  72.     if (i == 'y')
  73.         {
  74.         printf("Playing...\n");
  75.         set_play_que(0,elist.f); /* tell driver where track data is */
  76.         active_tracks(TRACK_1); /* tell MPU which tracks to play */
  77.         clear_play_counters(); /* must do to start from beginning of track */
  78.         play_start(); /* go */
  79.         while(!que_done()) /* could be doing something else here */
  80.             ;
  81.         }
  82.  
  83.     /* save it away for another day */
  84.     
  85.     printf("Saving Recording in file: %s\n",ofile);
  86.     save_list(&elist,ofile);
  87.     mpu_close();
  88.     }
  89.  
  90. /* simple  disk storage routine */
  91. save_list(struct eventlist *p, char *n)
  92.     {
  93.     int f = creat(n,0666);
  94.     struct event *ep = p->f,*oldep;
  95.     
  96.     /* walk the list, writing stuff out along the way */
  97.     while(ep)
  98.         {
  99.         write(f,&ep->tbyte,sizeof (ep->tbyte));
  100.         write(f,&ep->status,sizeof (ep->status));
  101.         write(f,&ep->dlen,sizeof(ep->dlen));
  102.         if (ep->dlen)
  103.             {
  104.             write(f,ep->d.data,ep->dlen);
  105.             }
  106.         oldep = ep;
  107.         ep = ep->n;
  108.         }
  109.     close(f);
  110.     }
  111.